<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<div th:replace="~{include-head :: head}"></div>
<div th:replace="~{include-modal-message-edit :: messageedit}"></div>
<link rel="stylesheet" type="text/css" href="/css/pagination.css"/>
<body>

<div th:replace="~{include-nav :: nav}"></div>
<div class="container-fluid">
    <div class="row">
        <div th:replace="~{include-sidebar :: sidebar}"></div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">#</th>
                                <th>消息描述</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody id="messageTableBody">
                            <!--ajax加载数据-->
                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="5" align="center">
                                    <div id="Pagination" class="pagination">
                                        <!-- 这里显示分页 -->
                                    </div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="/script/jquery.pagination.js"></script>
<script type="text/javascript" src="/script/my-message.js"></script>
<script type="text/javascript">

    //修改
    $("#messageTableBody").on("click",".editBtn",function(){


        window.messageId = $(this).attr("messageId");

        var messageName = $(this).parents("tr").children("td:eq(1)").text();



        $("#messageNameInputEdit").val(messageName);

        // 4.打开模态框
        $("#messageeditModal").modal("show");
    });


    //确认修改
    $("#editModalBtn").click(function () {
        // 1.获取文本框值
        var messageName = $.trim($("#messageNameInputEdit").val());

        if(messageName == null || messageName == "") {
            layer.msg("请输入有效角色名称！");

            return ;
        }
        $.ajax({
            url:"/message/update/message",
            type:"post",
            data:{
                "id":window.messageId,
                "content":messageName
            },
            dataType:"json",
            success:function (response) {
                var result = response.result;
                if(result == "SUCCESS") {
                    layer.msg("操作成功！");
                    // 3.操作成功重新分页
                    showPage();
                }
                if(result == "FAILED") {
                    layer.msg(response.message);
                }

                // 4.不管成功还是失败，关闭模态框
                $("#messageeditModal").modal("hide");
            }
        });
    });
</script>

